home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Game Pak
/
Shareware Game Pak For Windows.iso
/
spirals9
/
spirals9.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-18
|
5KB
|
147 lines
/*
SPIRALS9 12/18/91 v1.0 gjpateman
SPIRALS8 reads some of it's parameters from GJP.INI, then choses
a random rectangle on the Windows 3.0 screen. The rectangle is
duplicated "arms" times & spiraled outward from the center.
When an arm goes offscreen, it votes to exit the program (how
democratic!). When this vote becomes unanimous among the arms,
the program exits. While an arm is offscreen, the code to draw
it is skipped, thereby speeding up the arms which are visible.
Future enhancements:
Draw or don't draw border (in INI)
Use mouse/keyboard to abort
All parameters from GJP.INI
Window to set parameters
Use mouse to designate area to spiral
Show a message box before aborting if illegal .INI values.
Sample GJP.INI:
*/
#include <windows.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#define MODES 16
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
HDC hdc, hdcmem; // DC for screen & RAM
HBITMAP bitmap; // holds copied image
POINT src, dest; // source/dest locations
int scrnwidth, scrnheight;
char inifile[] = "GJP.INI",
app[] = "SPIRALS";
BOOL drawborder = 1;
WORD arm, arms,
modeindex,
votes_to_quit,
minwidth, maxwidth,
minheight, maxheight,
srcwidth, srcheight;
DWORD bitbltmodes[MODES] =
{
0, SRCCOPY, SRCPAINT, SRCAND, SRCINVERT, SRCERASE,
NOTSRCCOPY, NOTSRCERASE, MERGECOPY, MERGEPAINT,
PATCOPY, PATPAINT, PATINVERT, DSTINVERT, BLACKNESS,
WHITENESS
};
double r, rstep, rstepfact,
ang, angstep,
destwidth, destheight,
widthstep, heightstep,
offsetstep;
randomize();
// initialize variables from .INI file
arms = GetPrivateProfileInt(app, "arms", arms, inifile);
minwidth = GetPrivateProfileInt(app, "minwidth", minwidth, inifile);
minheight = GetPrivateProfileInt(app, "minheight", minheight, inifile);
maxwidth = GetPrivateProfileInt(app, "maxwidth", maxwidth, inifile);
maxheight = GetPrivateProfileInt(app, "maxheight", maxheight, inifile);
modeindex = GetPrivateProfileInt(app, "modeindex", modeindex, inifile);
drawborder = GetPrivateProfileInt(app, "drawborder", drawborder, inifile);
if(arms < 1) arms = 3;
if(minwidth < 1) minwidth = 5;
if(minheight < 1) minheight = 5;
if(maxheight < minheight) maxheight = minheight * 2;
if(maxwidth < minwidth) maxwidth = minwidth * 2;
if(modeindex < 1) modeindex = 1;
if(modeindex > MODES) modeindex = 1;
// initialize all other variables
hdc = CreateDC ("DISPLAY", NULL, NULL, NULL);
hdcmem = CreateCompatibleDC(hdc);
scrnwidth = GetSystemMetrics(SM_CXSCREEN);
scrnheight = GetSystemMetrics(SM_CYSCREEN);
srcwidth = minwidth + random(maxwidth - minwidth);
srcheight = minheight + random(maxheight - minheight);
destwidth = (double) srcwidth;
destheight = (double) srcheight;
widthstep = 1.03;
heightstep = 1.03;
src.x = random(scrnwidth - srcwidth);
src.y = random(scrnheight - srcheight);
offsetstep = (M_PI + M_PI) / (double)arms; // space between arms
bitmap = CreateCompatibleBitmap(hdc, srcwidth, srcheight);
rstep = 1.0;
rstepfact = 1.03;
ang = 0.0;
angstep = 0.04;
if(drawborder == 1)
{
MoveTo(hdc, src.x, src.y);
LineTo(hdc, src.x + srcwidth - 1, src.y);
LineTo(hdc, src.x + srcwidth - 1, src.y + srcheight - 1);
LineTo(hdc, src.x, src.y + srcheight - 1);
LineTo(hdc, src.x, src.y);
}
// save area to be "spiraled" into RAM DC
SelectObject(hdcmem, bitmap);
BitBlt(hdcmem, 0, 0, srcwidth, srcheight, hdc, src.x, src.y, SRCCOPY);
do // Spiral until unanimous vote to quit
{
votes_to_quit = 0; // new vote each time
for(arm = 0; arm < arms; ++arm)
{
// Calculate new position
dest.x = src.x + (int)(r * sin(ang + (arm * offsetstep)));
dest.y = src.y + (int)(r * cos(ang + (arm * offsetstep)));
// Draw rect ONLY if new position is completely/partially on-screen
if((dest.x + destwidth > 0) && (dest.x < scrnwidth) &&
(dest.y + destheight > 0) && (dest.y < scrnheight))
StretchBlt( hdc,
dest.x, dest.y,
(int)destwidth, (int)destheight,
hdcmem,
0, 0,
srcwidth, srcheight,
bitbltmodes[ modeindex ] );
else
++votes_to_quit;
}
destheight *= heightstep;
destwidth *= widthstep;
r += rstep;
rstep *= rstepfact;
ang += angstep;
} while ( votes_to_quit != arms ); // is it unanimous yet?
DeleteDC(hdc);
DeleteDC(hdcmem);
return 0;
}